﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NS_QuangCaoTiepThiBUS
{
    public class LoaiNguoiDungBUS
    {
        public void Them(LoaiNguoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            storeDB.LoaiNguoiDungs.InsertOnSubmit(lndDTO);

            storeDB.SubmitChanges();
        }

        public void Sua(LoaiNguoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNguoiDungs.Where(q => q.MaLoaiNguoiDung == lndDTO.MaLoaiNguoiDung).First();

            query.TenLoaiNguoiDung = lndDTO.TenLoaiNguoiDung;

            storeDB.SubmitChanges();
        }

        public void Xoa(LoaiNguoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNguoiDungs.Where(q => q.MaLoaiNguoiDung == lndDTO.MaLoaiNguoiDung).First();

            storeDB.LoaiNguoiDungs.DeleteOnSubmit(query);

            storeDB.SubmitChanges();
        }

        public IList<LoaiNguoiDung> LayDanhSachLoaiNguoiDung()
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNguoiDungs.ToList();

            return query;
        }

        public bool KiemTraTonTaiLoaiNguoiDung(LoaiNguoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNguoiDungs.Where(q => q.MaLoaiNguoiDung == lndDTO.MaLoaiNguoiDung).ToList();

            if (query.Count > 0)
            {
                return true;
            }

            return false;
        }
    }
}
